package Model.Diagrams;

import Model.Core.IEntity;
import java.util.ArrayList;
import java.util.List;

/**
 * Projeto de TCC: Editor de Diagramas de Comunicação em UML.
 * @author Jose
 */
public class CommunicationDiagram {

    private List<IEntity> entities;

    public CommunicationDiagram() {
        this.entities = new ArrayList<IEntity>();
    }

    public void addEntity(IEntity entity) {
        entities.add(entity);
    }

    public void removeEntity(IEntity entity) {
        entities.remove(entity);
    }

    public boolean isDuplicatedEntity(IEntity entity) {
        return entities.contains(entity);
    }

    public List<IEntity> getEntities() {
        return entities;
    }

    public void checkNameEntity(IEntity currentEntity) {
        int index = 0;
        String reference = currentEntity.getDescription();
        for (IEntity entity : entities) {
            if (entity.getClass() == currentEntity.getClass() && !entity.equals(currentEntity)) {
                if (index > 0) {
                    reference = currentEntity.getDescription() + "(" + index + ")";
                }
                if (entity.getDescription().equalsIgnoreCase(reference)) {
                    index++;
                }
            }
        }
        if (index > 0) {
            currentEntity.setDescription(currentEntity.getDescription() + "(" + index + ")");
        }
    }
}